/**
 *******************************************************************************
 *  @copyright Copyright (c) 2022  <dx_65535@163.com>. 
 * 
 *  @file demo_uart_test.cc
 *  @author Xiang.D (dx_65535@163.com)
 *  @version 1.0
 *  @brief Blog: https://linuxtaoist.gitee.io
 *  @date 2022-06-19
 * 
 * 
 *  Change History:
 *  <Date>     | <Version> | <Author>       | <Description>
 *------------------------------------------------------------------------------
 *  2022/06/19 | 1.0.0.1   | Xiang.D        | Create file
 *------------------------------------------------------------------------------
 * 
 *******************************************************************************
 */

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "common_type.h"
#include "event_handler.h"

#define LOGD(fmt, args...) printf("%d DemoUart D: " fmt, __LINE__, ##args)
#define LOGE(fmt, args...) printf("%d DemoUart E: " fmt, __LINE__, ##args)

const char DEVICE_NAME[] = "/dev/pts/2";

int main(int argc, char *argv[])
{
    ssize_t ret;
    CEventHandler theEventHandler;
    theEventHandler.Init();

    int fd = open(DEVICE_NAME, O_RDWR | O_NOCTTY | O_NDELAY);
    if(fd < 0) {
        perror("Can't Open Serial Port");
        return -1;
    }

    theEventHandler.RegisterEvent(fd, CHANNEL_UART, NULL);

    theEventHandler.Run();

    ret = write(fd, "uart test!", 10);
    if (ret < 0) {
        perror("write failed!\n");
    } else {
        LOGD("write %ld data.\n", ret);
    }
    
    while(1);
    close(fd);
    return 0;
}

